package java8;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamPractice {
    public static int getSum(List<Integer> list) {
        return list.stream().reduce(0, (num1, num2) -> num1 + num2);
    }

    public static List<String> getArtistNamesAndNations(List<Artist> artists) {
        return artists.stream().flatMap(artist -> Stream.of(artist.getName(), artist.getNationality())).collect(Collectors.toList());
    }

    public static void main(String[] args) {
        System.out.println(getSum(Arrays.asList(1, 2, 3, 4, 5)));
        List<Artist> artists = new ArrayList<>();
        artists.add(new Artist("john", "china", "male"));
        artists.add(new Artist("jack", "china", "male"));
        artists.add(new Artist("tom", "china", "male"));
        artists.add(new Artist("joy", "china", "male"));
        artists.add(new Artist("jerry", "china", "female"));

        getArtistNamesAndNations(artists).stream().forEach(System.out::println);
//        artists.stream().map(artist -> artist.getMembers().count())
//                .reduce((x, y) -> x + y);

    }
}
